module.exports = {

    /**
     * param 将要转为URL参数字符串的对象
     * key URL参数字符串的前缀
     * encode true/false 是否进行URL编码,默认为true
     * 
     * return URL参数字符串
     */
    urlEncode: function (param, key, encode) {
        if (param == null) return '';
        var paramStr = '';
        var t = typeof (param);
        if (t == 'string' || t == 'number' || t == 'boolean') {
            paramStr += '&' + key + '=' + ((encode == null || encode) ? encodeURIComponent(param) : param);
        } else {
            for (var i in param) {
                var k = key == null ? i : key + (param instanceof Array ? '[' + i + ']' : '.' + i);
                paramStr += this.urlEncode(param[i], k, encode);
            }
        }
        return paramStr;
    },
    /**
     * 鼠标滚轮事件监听
     */
    callbacks: [],
    mouseWheel: function (callback) {
        this.callbacks.push(callback)
        var callbacks = this.callbacks
        function fn(event) {
            var event = event || window.event;
            var target = event.target || event.srcElement;
            var direct = - event.wheelDelta || event.detail;
            callbacks.forEach(callback => {
                callback(event, target, direct)
            });
        }
        if (window.addEventListener) {
            document.addEventListener('DOMMouseScroll', fn, false);
        }
        window.onmousewheel = document.onmousewheel = fn;
    }
}